
package DAO;

import BE.MenuBE;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MenuDAO {

    public MenuDAO() {
    }
    public List<MenuBE> listaMenuPrinciapal(){ //metodo
        
        List<MenuBE> lista = new ArrayList();
        String sql = "select id_menu,id_menusup,nombre_menu,orden,formulario from tabla_menu where id_menusup is null";
        
        Connection c = new BD().obtieneConexion();
        Statement st = null;

        try {
            st = c.createStatement();
            ResultSet rt = st.executeQuery(sql);//obtiene toda la consulta de la BD
            while(rt.next()){
                MenuBE objMenu = new MenuBE();
                
                objMenu.setId_menu(rt.getInt("id_menu"));
                objMenu.setId_menusup(rt.getInt("id_menusup"));
                objMenu.setNombre_menu(rt.getString("nombre_menu"));
                objMenu.setOrden(rt.getString("orden"));
                objMenu.setFormulario(rt.getString("formulario"));
                lista.add(objMenu);
            }
        } catch (SQLException ex) {
            Logger.getLogger(MenuDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
               
        return lista;
    }
// ----------------- SUB MENU -----------------------------
    
public List<MenuBE> listaSubMenu(int sup){ //metodo
List<MenuBE> listaSubMenu = new ArrayList();
String sql ="select id_menu,id_menusup,nombre_menu,orden,formulario from tabla_menu where id_menusup = "+sup;
Connection c = new BD().obtieneConexion();
Statement st = null;
 try {
   st = c.createStatement();
   ResultSet rt = st.executeQuery(sql);
   while(rt.next()){
                MenuBE objMenu = new MenuBE();
                
       objMenu.setId_menu(rt.getInt("id_menu"));
                objMenu.setId_menusup(rt.getInt("id_menusup"));
                objMenu.setNombre_menu(rt.getString("nombre_menu"));
                objMenu.setOrden(rt.getString("orden"));
                objMenu.setFormulario(rt.getString("formulario"));
                listaSubMenu.add(objMenu);
            }

   } catch (SQLException ex) {
 Logger.getLogger(MenuDAO.class.getName()).log(Level.SEVERE, null, ex);
 }

return listaSubMenu;
}
}

